package com.android.demo;

import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.android.demo.widget.Mask;

public class TestMask extends Activity implements OnClickListener {

    private LinearLayout reload;
    private View mask;
    RelativeLayout parent;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mask_main);

        // 获取屏幕宽高
        DisplayMetrics dm = new DisplayMetrics();
        dm = getApplicationContext().getResources().getDisplayMetrics();
        int screenWidth = dm.widthPixels;
        int screenHeight = dm.heightPixels;

        parent = (RelativeLayout) findViewById(R.id.mask_parent);

        // 新建遮罩
        mask = new Mask(this, screenWidth, screenHeight);

        parent.addView(mask);

        startOpenAnimation();
        
        // 点击屏幕重启遮罩动画
        reload = (LinearLayout) findViewById(R.id.reload);
        reload.setOnClickListener(this);

    }

    private void startOpenAnimation() {

        TranslateAnimation ta = new TranslateAnimation(0, 0, 0, getApplicationContext().getResources().getDisplayMetrics().heightPixels);
        ta.setDuration(2000);
        ta.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationEnd(Animation animation) {
                mask.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

            @Override
            public void onAnimationStart(Animation animation) {

            }

        });
         mask.startAnimation(ta);
    }

    @Override
    public void onClick(View v) {

        startOpenAnimation();
    }
}